<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
 <%@ include file="/common/query.jsp"%>
<%@ include file="/common/det.jsp"%>
<script>
    var productCategoryAttrgroupAttrId = getQueryStringByDecode("productCategoryAttrgroupAttrId");
        $(function(){
            init();
        });
        function init(){
            var setting = {};
            var url ="";
            var p_insert = false;
            var p_del = false;

            var edit = true;
            var del = true;




            //crudDefaultInputWidth = "250px";
            crudDialogWidth = 300;
            var columns = [
                {field:'id',title:'id',hidden:true},
                {field:'productAttrValue',title:'属性值',
                    dialog:{
                        url:"${base}/product/attr/value?search=false&singleSelect=true&productCategoryAttrgroupAttrId="+productCategoryAttrgroupAttrId,
                        select:function(iframe){
                            var row = iframe.getGridChecked()[0];
                            $('#crud-productAttrValueId').val(row.id);
                            $('#crud-productAttrValue').val(row.productAttrValue);
                        }
                    }
				},
                {field:'productCategoryAttrgroupAttrId',title:'productCategoryAttrgroupAttrId',hidden:true,defaultValue:productCategoryAttrgroupAttrId},
                {field:'productAttrValueId',title:'productAttrValueId',hidden:true}
            ];
            url='/product/category/attrgroup/attr/value/manager?search_EQ_productCategoryAttrgroupAttrId='+productCategoryAttrgroupAttrId;
            //setting.singleSelec	t = true;
            createQuery('body',columns,
				{
				    pager:false,edit:edit,editBtn:false,add:false,searchBar:{hidden:true},del:del,heji:false,xuhao:false,cb:false,
                    toolbar:[{
                        text : '<a  class="pure-button pure-button-primary" >添加</a>',
                        handler : tianjia
                    }]
				},
				url);
        };

        function tianjia() {
            layer.open({
                type: 2,
                title: "添加",
                shadeClose: true,
                shade: 0.8,
                area: ['380px', '90%'],
                content: "${base}/product/attr/value?search=false&singleSelect=true&productCategoryAttrgroupAttrId="+productCategoryAttrgroupAttrId,
                btn:['确定'],
                yes: function (index, layero) {
                    var rows = $(layero).find("iframe")[0].contentWindow.getGridChecked();
                    if(rows.length>0){
                        var ids = "";
                        for(var i =0 ;i<rows.length;i++){
                            var row = rows[i];
                            ids += ','+row.id;
                        }
                        ids = ids.substr(1);
                        $.ajax({
                            type : 'post',
                            url : '${base}/product/category/attrgroup/attr/value/batchAddAttrValue',
                            data : {
                                productCategoryAttrgroupAttrId:productCategoryAttrgroupAttrId,
                                ids:ids
                            },
                            async:false,
                            dataType : 'json',
                            success :  function(res){
                                if(res.code==-1){
                                    alert(res.msg);
                                }else{
                                    search();
                                }
                            }
                        })
                    }
                    layer.close(index);
                },
            });


        }
        

</script>
</head>
<body>
	  <div id="body"></div>
</body>
</html>